package compare;

import java.io.Serializable;
import java.text.Collator;
import java.util.*;
import java.util.stream.Collectors;

/**
 * TODO:类描述
 *
 * @className: A
 * @packageName: PACKAGE_NAME
 * @author: Zhuhj
 * @version: V1.0
 * @date: 2021/4/10 22:41
 */
public class CompareTest implements Serializable {
    private static final long serialVersionUID = -5362330504532103641L;
    private String a;




    public static void main(String[] args) throws Exception {
       Map<String,Object> o1= new HashMap<>();
       o1.put("handleDate","2012");
        o1.put("age",3);
        Map<String,Object> o2= new HashMap<>();
        o2.put("handleDate","2013");
        o2.put("age",4);
        Map<String,Object> o3= new HashMap<>();
        o3.put("handleDate","2011");
        o3.put("age",2);
        List<Map<String,Object>> list = new ArrayList<>();
        list.add(o1);
        list.add(o2);
        list.add(o3);
        System.out.println(list);
      //  Collections.sort(list, (Comparator<Map<String, Object>>) (o11, o21) -> -o11.get("handleDate").toString().compareTo(o21.get("handleDate").toString()));
//        Collections.sort(list,Comparator.comparing(o->o.get("handleDate").toString(),Comparator.reverseOrder()));
        Collections.sort(list,Comparator.comparing(o->o.get("handleDate").toString(),Comparator.reverseOrder()));
        System.out.println(list);
        Comparator<Map<String,Object>> x = Comparator.comparing(o->o.get("age").toString(),Comparator.reverseOrder());
        Comparator<Map<String,Object>> x1 = Comparator.comparing(o->o.get("handleDate").toString(),Comparator.naturalOrder());
        list.sort(x.thenComparing(x1));
        //List<Map<String,Object>> list1 = list.stream().sorted(x.thenComparing(x1)).collect(Collectors.toList());
        System.out.println(list);




    }
}
